home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ML_3DROT.ZIP / SOURCES / FIG11.PAS < prev    next >
Pascal/Delphi Source File  |  1996-12-26  |  3KB  |  140 lines

  1. {
  2.   Example of using the 3D "engine", by Maple Leaf, 1996
  3.  
  4.   This code is freeware. If you find it useful, feel free to do whatever
  5.   you want with it, with only one condiion: give some small greetings to
  6.   Maple Leaf in your productions that use parts of it.
  7.  
  8.                                                         Maple Leaf, '96
  9.  
  10.   btw, I'm too lazy to write down kilos of comments...   :-)
  11. }
  12. uses xmode,crt,engine3d;
  13.  
  14. var a,b:word;
  15.     pal:array[byte] of record r,g,b:byte end;
  16.     capag,cvpag : word;
  17.     dd:integer;
  18.     coord:array[0..730] of record x,y,z:integer end;
  19.     RealMapping : Boolean;
  20.     ch:char;
  21.     MaxPnt:word;
  22.     RotStep,TiltStep:longint;
  23.  
  24. Procedure GenFig;
  25. var cnt,k:word; angle,angle2,rad:real;
  26. begin
  27.   cnt:=0;
  28.   angle:=0;
  29.   k:=0;
  30.   repeat
  31.     angle2:=0;
  32.     rad:=abs(40*sin(angle));
  33.     repeat
  34.       with coord[cnt] do begin
  35.         x:=Trunc(rad*cos(angle2*pi/180));
  36.         y:=Trunc(rad*sin(angle2*pi/180));
  37.         z:=k*6;
  38.       end;
  39.       inc(cnt);
  40.       angle2:=angle2+10; {?}
  41.     until (cnt>720) or (angle2>=360);
  42.     angle:=angle+2*pi/19; {?}
  43.     inc(k);
  44.   until cnt>720;
  45.   MaxPnt:=cnt
  46. end;
  47.  
  48. Procedure PuneFig;
  49. var i:integer; cnt:word;
  50. begin
  51.   cnt:=0;
  52.   {xvwait;}
  53.   xclrvpage(capag);
  54.   for i:=0 to MaxPnt-1 do begin
  55.     _3dx:=coord[i].x+100;
  56.     _3dy:=coord[i].y;
  57.     _3dz:=coord[i].z+10;
  58.     asm
  59.        cmp RealMapping,1
  60.        je @1
  61.        call IntMapCoordinates
  62.        jmp @2
  63.     @1:call MapCoordinates
  64.     @2:
  65.     end;
  66.     xvplot(_2dx,_2dy,i shr 2,capag);
  67.   end;
  68. end;
  69.  
  70. Procedure IntroText;
  71. begin
  72.   Writeln('3D Figure, by Maple Leaf, 1996.');
  73.   Writeln(#13#10,' Hot keys are:'#13#10);
  74.   Writeln('   <M>     - Change mapping method (float/integer)');
  75.   Writeln('   <Left>  - Decrement horizontal speed of rotation');
  76.   Writeln('   <Right> - Increment horizontal speed of rotation');
  77.   Writeln('   <Up>    - Increment vertical speed of rotation');
  78.   Writeln('   <Down>  - Decrement vertical speed of rotation');
  79.   Writeln(#13#10'Press a key to start ...');
  80.   Readkey;
  81. end;
  82.  
  83. begin
  84.   ClrScr;
  85.   GenFig;
  86.   IntroText;
  87.   xinitvideo(0);
  88.   xclrvram;
  89.   for a:=1 to 255 do with pal[a] do begin
  90.     r:=Trunc(63*a/255);
  91.     g:=Trunc(40);
  92.     b:=Trunc(63-63*a/255);
  93.   end;
  94.   xsetpalette(@pal);
  95.   ZoomFactor:=500;
  96.   Perspective:=True;
  97.   SetObserverPosition(0,0,500);
  98.   SetAngles(0,0);
  99.   capag:=0;
  100.   cvpag:=3;
  101.   dd:=10;
  102.   RealMapping:=false;
  103.   RotStep:=2;
  104.   TiltStep:=3;
  105.   repeat
  106.    repeat
  107.  
  108.     xvwait;
  109.     xsetvpage(cvpag);
  110.  
  111.     RotAngle:=RotAngle+RotStep;
  112.     TiltAngle:=TiltAngle+TiltStep;
  113.     if RotAngle>359 then RotAngle:=360-RotAngle;
  114.     if RotAngle<0 then RotAngle:=360+RotAngle;
  115.     if TiltAngle>359 then TiltAngle:=360-TiltAngle;
  116.     if TiltAngle<0 then TiltAngle:=360+TiltAngle;
  117.     {SetAngles(RotAngle,TiltAngle);}
  118.  
  119.     PuneFig;
  120.  
  121.     inc(capag); if capag>3 then capag:=0;
  122.     inc(cvpag); if cvpag>3 then cvpag:=0;
  123.  
  124.    until keypressed;
  125.    ch:=readkey;
  126.    case UpCase(ch) of
  127.      'M': { Mapping mode } RealMapping:=not RealMapping;
  128.      #0: begin
  129.        ch:=readkey;
  130.        case ch of
  131.          #72: {Up}    inc(RotStep);
  132.          #80: {Down}  dec(RotStep);
  133.          #75: {Left}  dec(TiltStep);
  134.          #77: {Right} inc(TiltStep);
  135.        end;
  136.      end;
  137.    end;
  138.   until ch=#27;
  139.   textmode(25);
  140. end.